/*
 ============================================================================
 Name        : CommandParser.h
 Author      : Sherry Krikszer
 Version     : 1.0
 Copyright   :
 Description : in C, Ansi-style
 ============================================================================
 */

#ifndef COMMANDPARSER_H_
#define COMMANDPARSER_H_

#include "Common.h"
#include "AssemblerCommon.h"

/* ----------------------------------------------------------------------------
 *	Constants Definition
 * ----------------------------------------------------------------------------*/

#define MAX_ADDRESSING_METHODS_NUMBER 	5

/* ----------------------------------------------------------------------------
 *	Constants Definition End
 * ----------------------------------------------------------------------------*/

/* ----------------------------------------------------------------------------
 *	Type Definition
 * ----------------------------------------------------------------------------*/

/* Command parsing result */
typedef struct
{
	Boolean 			hasParseSucceded;
	ErrorMessage 		parsingErrorMessage;
	char*				commandName;
	CommandOperands		parsedCommand;
}ParseResult;

/* A function, that takes a string array (parameters) and an integer (parameter count)
 *  and returns a pointer to the parsed command */
typedef ParseResult (*CommandParser)(char**, int);

typedef struct
{
	CommandType 		commandType;
	char* 				commandName;
	unsigned int 		commandOpcode :4;
	unsigned int 		expectedParametersCount;
	CommandParser 		commandParser;
	AddressingMethod 	allowedAddressingMethods[MAX_OPERANDS_PER_COMMAND][MAX_ADDRESSING_METHODS_NUMBER];
}CommandDetail;

typedef struct
{
	int numberOfWordUsed;
	int opcode;
}AddressingMethodDetail;

/* ----------------------------------------------------------------------------
 *	Type Definition End
 * ----------------------------------------------------------------------------*/

/* ----------------------------------------------------------------------------
 *	Function Declaration
 * ----------------------------------------------------------------------------*/

ParseResult ParseAssemblerCommand (char* commandName, Params params);
Boolean 				DoesContainCommand(char* commandName);
AddressingMethodDetail 	GetAddressingMethodDetail(AddressingMethod addressingMethod);

CommandParser GetMatchingCommandParser(char* commandName);
CommandDetail* GetCommandDetailByName(char* commandName);
CommandDetail* GetCommandDetailByType(CommandType commandTypeToSearch);

Boolean IsValidLabel (char* symbol, char* invalidMessage);
Boolean IsValidNumberParameter	(char* numberParameterString);
Boolean IsValidStringParameter (char* parameterString, char* invalidMessage);

/* ----------------------------------------------------------------------------
 *	Function Declaration End
 * ----------------------------------------------------------------------------*/

#endif /* COMMANDPARSER_H_ */
